package com.szholly.plug.arcgis.controller;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.szholly.plug.arcgis.entity.GisConfigLodsRow;
import com.szholly.plug.arcgis.entity.GisConfigLodsTable;
import com.szholly.plug.arcgis.entity.GisConfigRow;
import com.szholly.plug.arcgis.entity.GisConfigTable;
import com.szholly.data.general.QueryMap;
import com.szholly.data.general.RowBase;

/**
 * 定义GIS配置控制器
 */
@Controller
public class ConfigController {
	
	/**
	 * 设置默认GIS配置信息
	 */
	@RequestMapping(value = "/gis/defulatconfig.do")
	public void setDefulatConfig(HttpServletRequest request,
			HttpServletResponse response){
		// 删除所有配置
		GisConfigTable.getSingleRef().delete(new QueryMap());
		
		GisConfigRow configRow = new GisConfigRow();
		configRow.setDCenterx(113.270107);
		configRow.setDCentery(22.90625);
		
		configRow.setSDrawfillcolor("#ff0000");
		configRow.setSDrawstrokecolor("#ff0000");
		configRow.setDDrawfillopacity(0.8);
		
		configRow.setSDefaultfillcolor("#FBDF55");
		configRow.setSDefaultstrokecolor("#666666");
		configRow.setDDefaultfillopacity(0.8);
		
		configRow.setSSelectfillcolor("#E697D9");
		configRow.setSSelectstrokecolor("#666666");
		configRow.setDSelectfillopacity(0.5);
		
		configRow.setIInilevel(4);
		configRow.setMaxLevel(18);
		configRow.setMinLevel(0);
		configRow.setSFullextent("108.726560572,19.576929032,118.839032788,25.794226955");
		configRow.setSIniextent("108.726560572,19.576929032,118.839032788,25.794226955");
		configRow.setDLWkid("4326");
		configRow.setTYWkid("102100");
		configRow.setMapIsDlWkid("1");
		
		configRow.setLocator("http://localhost:6080/arcgis/rest/services/FindLocator/GeocodeServer");
		configRow.setRLocator("http://localhost:6080/arcgis/rest/services/FindLocator/GeocodeServer");
		configRow.setLocatorDefName("广东省");
		configRow.setLocatorHot("北京市 上海市 深圳市 长沙市");
		configRow.setLocatorTableName("data_defulatdomain");
		configRow.setLocatorDomainName("政区");
		configRow.setLocatorOrder("I_ORDER:1");
		configRow.setLocatorJbs("1,2");
		
		configRow.setGeometryServer("http://localhost:6080/arcgis/rest/services/Utilities/Geometry/GeometryServer");
		configRow.setPrintingServer("http://localhost:6080/arcgis/rest/services/Utilities/PrintingTools/GPServer");
		
		// 删除所有级别
		List<RowBase> lodsList = new ArrayList<RowBase>();
		
		GisConfigLodsRow lodsRow = new GisConfigLodsRow();
		lodsRow.setILevel(0);
		lodsRow.setResolution("1.40625");
		lodsRow.setScale("590995186.11750006");
		lodsRow.setSTitle("");
		lodsList.add(lodsRow);
		
		lodsRow = new GisConfigLodsRow();
		lodsRow.setILevel(1);
		lodsRow.setResolution("0.703125");
		lodsRow.setScale("295497593.05875003");
		lodsRow.setSTitle("");
		lodsList.add(lodsRow);
		
		lodsRow = new GisConfigLodsRow();
		lodsRow.setILevel(2);
		lodsRow.setResolution("0.3515625");
		lodsRow.setScale("147748796.52937502");
		lodsRow.setSTitle("");
		lodsList.add(lodsRow);

		lodsRow = new GisConfigLodsRow();
		lodsRow.setILevel(3);
		lodsRow.setResolution("0.17578125");
		lodsRow.setScale("73874398.264687508");
		lodsRow.setSTitle("");
		lodsList.add(lodsRow);
		
		lodsRow = new GisConfigLodsRow();
		lodsRow.setILevel(4);
		lodsRow.setResolution("0.087890625");
		lodsRow.setScale("36937199.132343754");
		lodsRow.setSTitle("");
		lodsList.add(lodsRow);
		
		lodsRow = new GisConfigLodsRow();
		lodsRow.setILevel(5);
		lodsRow.setResolution("0.0439453125");
		lodsRow.setScale("18468599.566171877");
		lodsRow.setSTitle("");
		lodsList.add(lodsRow);
		
		lodsRow = new GisConfigLodsRow();
		lodsRow.setILevel(6);
		lodsRow.setResolution("0.02197265625");
		lodsRow.setScale("9234299.7830859385");
		lodsRow.setSTitle("");
		lodsList.add(lodsRow);
		
		lodsRow = new GisConfigLodsRow();
		lodsRow.setILevel(7);
		lodsRow.setResolution("0.010986328125");
		lodsRow.setScale("4617149.8915429693");
		lodsRow.setSTitle("");
		lodsList.add(lodsRow);
		
		lodsRow = new GisConfigLodsRow();
		lodsRow.setILevel(8);
		lodsRow.setResolution("0.0054931640625");
		lodsRow.setScale("2308574.9457714846");
		lodsRow.setSTitle("市");
		lodsList.add(lodsRow);

		lodsRow = new GisConfigLodsRow();
		lodsRow.setILevel(9);
		lodsRow.setResolution("0.00274658203125");
		lodsRow.setScale("1154287.4728857423");
		lodsRow.setSTitle("县");
		lodsList.add(lodsRow);
		
		lodsRow = new GisConfigLodsRow();
		lodsRow.setILevel(10);
		lodsRow.setResolution("0.001373291015625");
		lodsRow.setScale("577143.73644287116");
		lodsRow.setSTitle("乡");
		lodsList.add(lodsRow);
		
		lodsRow = new GisConfigLodsRow();
		lodsRow.setILevel(11);
		lodsRow.setResolution("0.0006866455078125");
		lodsRow.setScale("288571.86822143558");
		lodsRow.setSTitle("村");
		lodsList.add(lodsRow);
		
		lodsRow = new GisConfigLodsRow();
		lodsRow.setILevel(12);
		lodsRow.setResolution("0.00034332275390625");
		lodsRow.setScale("144285.93411071779");
		lodsRow.setSTitle("");
		lodsList.add(lodsRow);

		lodsRow = new GisConfigLodsRow();
		lodsRow.setILevel(13);
		lodsRow.setResolution("0.000171661376953125");
		lodsRow.setScale("72142.967055358895");
		lodsRow.setSTitle("");
		lodsList.add(lodsRow);
		
		lodsRow = new GisConfigLodsRow();
		lodsRow.setILevel(14);
		lodsRow.setResolution("0.0000858306884765625");
		lodsRow.setScale("36071.483527679447");
		lodsRow.setSTitle("");
		lodsList.add(lodsRow);

		lodsRow = new GisConfigLodsRow();
		lodsRow.setILevel(15);
		lodsRow.setResolution("0.0000429153442382812");
		lodsRow.setScale("18035.741763839724");
		lodsRow.setSTitle("");
		lodsList.add(lodsRow);
		
		lodsRow = new GisConfigLodsRow();
		lodsRow.setILevel(16);
		lodsRow.setResolution("0.0000214576721191406");
		lodsRow.setScale("9017.8708819198619");
		lodsRow.setSTitle("");
		lodsList.add(lodsRow);
		
		lodsRow = new GisConfigLodsRow();
		lodsRow.setILevel(17);
		lodsRow.setResolution("0.0000107288360595703");
		lodsRow.setScale("4508.9354409599309");
		lodsRow.setSTitle("");
		lodsList.add(lodsRow);
		
		lodsRow = new GisConfigLodsRow();
		lodsRow.setILevel(18);
		lodsRow.setResolution("5.36441802978515E-06");
		lodsRow.setScale("2254.4677204799655");
		lodsRow.setSTitle("");
		lodsList.add(lodsRow);
		
		configRow.setChildValues(new HashMap<String,List<RowBase>>());
		configRow.getChildValues().put(GisConfigLodsTable.TABLE_NAME, lodsList);
		
		GisConfigTable.getSingleRef().save(configRow);
	}
}